layui.use(['element','laypage', 'layer'], function(){
    var element = layui.element;
    var laypage = layui.laypage
        ,layer = layui.layer;


});


$(function () {


    initLayPage();

    var key = $("#key").val();
    var reads = window.localStorage.getItem("tagReads");
    reads = JSON.parse(reads);
    if(reads == null){
        reads = [];
        reads.push(key);
        window.localStorage.setItem("tagReads",JSON.stringify(reads));
        readCount(key);
    }else{
        if(reads.indexOf(key) == -1){
            //没有阅读过，阅读量+1
            reads.push(key);
            window.localStorage.setItem("tagReads",JSON.stringify(reads));
            readCount(key);
        }
    }


})

/**
 * 查看文章详情页面
 * @param id
 */
function  desc(typeid,id) {
    location.href = "/article/"+id;
}

function readCount(key){
    //保存项目
    $.ajax({
        url:"/tag/updateCount",
        type:"POST",
        data: {
            key:key
        },
        // contentType:"application/json;charset=utf-8",
        success:function (result) {

        },
        error:function (res) {
            console.log(res);
        }
    });
}

function initLayPage(pageConf) {
    if(!pageConf){
        pageConf = {};
        pageConf.limit = 10;
        pageConf.page = 1;
    }


    layui.use(['element','laypage', 'layer'], function(){
                var element = layui.element;
                var laypage = layui.laypage
                    ,layer = layui.layer;

                var pageData = $("#pageData").val();
                var page = JSON.parse(pageData);
                var key = $("#key").val();

                laypage.render({
                    elem: 'page'
                    ,count: page.count
                    ,curr:page.page
                    ,limit:page.limit
                    ,theme: '#1E9FFF'
                    ,jump:function (obj,first) {
                        //首次不执行
                        if(!first){
                            location.href = "/tag/"+key+"?page="+obj.curr+"&limit="+obj.limit;
                        }
                    }
                });
            });
}


